let StateZeroArr=[0,0,0,0,0,0,0];//查询0 待付款
let StateOneArr=[0,0,0,0,0,0,0];//查询1待发货
let StateTwoArr=[0,0,0,0,0,0,0];//查询2待收货
let StateThreeArr=[0,0,0,0,0,0,0];//查询3已收货
let StateFourArr=[0,0,0,0,0,0,0];//查询4售后
let StateFiveArr=[0,0,0,0,0,0,0];//查询5已取消
layui.config({
	version:'1510164124181'
}).use(['form','laydate', 'laypage', 'layer', 'element'],function(){
	form = layui.form;
	layer = layui.layer;
	laydate = layui.laydate;//日期
	laypage = layui.laypage;//分页
	element = layui.element; //元素操作
	TitleInfo();
	Productlist();//商品销量排序
	LoginRecord();//登录记录
	CountStateList();//订单状态统计
	SelectChart();//条形统计图
});
function SelectChart() {
	$.ajax({
		url: httpurl+"/HomePageSelectChart",
		cache: false,
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		success: function(data){
			if(data.rtnCode==200){
				let dataList=data.data;
				HandleSelectChart(dataList);
			}else{
				top.layer.alert("访问接口失败！！",function(index){
					layer.close(index);
				});
			}
		}
	});
}
function HandleSelectChart(dataList) {
	let StateZero=dataList.StateZero;
	let StateOne=dataList.StateOne;
	let StateTwo=dataList.StateTwo;
	let StateThree=dataList.StateThree;
	let StateFour=dataList.StateFour;
	let StateFive=dataList.StateFive;

	for(let i=0;i<StateZero.length;i++){
		tempInfo = parseInt(StateZero[i].keyInfo);
		StateZeroArr[tempInfo]=(StateZero[i].valInfo==null?0:parseFloat(StateZero[i].valInfo));
	}
	for(let i=0;i<StateOne.length;i++){
		tempInfo = parseInt(StateOne[i].keyInfo);
		StateOneArr[tempInfo]=(StateOne[i].valInfo==null?0:parseFloat(StateOne[i].valInfo));
	}
	for(let i=0;i<StateTwo.length;i++){
		tempInfo = parseInt(StateTwo[i].keyInfo);
		StateTwoArr[tempInfo]=(StateTwo[i].valInfo==null?0:parseFloat(StateTwo[i].valInfo));
	}

	for(let i=0;i<StateThree.length;i++){
		tempInfo = parseInt(StateThree[i].keyInfo);
		StateThreeArr[tempInfo]=(StateThree[i].valInfo==null?0:parseFloat(StateThree[i].valInfo));
	}

	for(let i=0;i<StateFour.length;i++){
		tempInfo = parseInt(StateFour[i].keyInfo);
		StateFourArr[tempInfo]=(StateFour[i].valInfo==null?0:parseFloat(StateFour[i].valInfo));
	}

	for(let i=0;i<StateFive.length;i++){
		tempInfo = parseInt(StateFive[i].keyInfo);
		StateFiveArr[tempInfo]=(StateFive[i].valInfo==null?0:parseFloat(StateFive[i].valInfo));
	}
	var dom = document.getElementById("countInfo");
	var myChart = echarts.init(dom);
	var app = {};
	app.title = '堆叠条形图';
	let option = {
		title: {
			text: '数据分析'
		},
		tooltip: {
			trigger: 'axis',
			axisPointer: {            // 坐标轴指示器，坐标轴触发有效
				type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			}
		},
		legend: {
			data: ['待付款', '待发货', '待收货', '已收货', '已取消']
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true
		},
		xAxis: {
			type: 'value'
		},
		yAxis: {
			type: 'category',
			data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
		},
		series: [
			{
				name: '待付款',
				type: 'bar',
				stack: '总量',
				label: {
					normal: {
						show: true,
						position: 'insideRight'
					}
				},
				data: StateZeroArr
			},
			{
				name: '待发货',
				type: 'bar',
				stack: '总量',
				label: {
					normal: {
						show: true,
						position: 'insideRight'
					}
				},
				data: StateOneArr
			},
			{
				name: '待收货',
				type: 'bar',
				stack: '总量',
				label: {
					normal: {
						show: true,
						position: 'insideRight'
					}
				},
				data:StateTwoArr
			},
			{
				name: '已收货',
				type: 'bar',
				stack: '总量',
				label: {
					normal: {
						show: true,
						position: 'insideRight'
					}
				},
				data:StateThreeArr
			},
			{
				name: '已取消',
				type: 'bar',
				stack: '总量',
				label: {
					normal: {
						show: true,
						position: 'insideRight'
					}
				},
				data:StateFiveArr
			}
		]
	};
	if (option && typeof option === "object") {
		myChart.setOption(option, true);
	}
}
function CountStateList() {
	$.ajax({
		url: httpurl+"/CountStateList",
		cache: false,
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		success: function(data){
			if(data.rtnCode==200){
				let dataList=data.data;
				HandleCountStateList(dataList);
			}else{
				top.layer.alert("访问接口失败！！",function(index){
					layer.close(index);
				});
			}
		}
	});
}
function HandleCountStateList(dataInfo) {
	let TbInfo="";
	let TableInfo='<tr><td colspan="2" class="bg_gray"><a href="order/OrderList.html" >所有订单信息</a></td></tr>';
	for(let i=0;i<dataInfo.length;i++){
		let OState=(dataInfo[i].keyInfo==0?"待付款":(dataInfo[i].keyInfo==1?"待发货":dataInfo[i].keyInfo==2?"待收货":dataInfo[i].keyInfo==3?"已收货":(dataInfo[i].keyInfo==4?"售后":(dataInfo[i].keyInfo==5?"已取消":"异常"))));
		TbInfo+='<td>'+
					'<a href="order/OrderList.html" ><div class="width60 float_left">'+OState+'</div></a>'+
					'<div class="width40 float_left">'+
						'<span class="text-info" id="dfk">'+dataInfo[i].valInfo+'</span>'+
					'</div>'+
				'</td>';
		if((i+1)%2==0){
			TableInfo+='<tr>'+TbInfo+'</tr>';
			TbInfo="";
		}
	}
	$(".OrderStateTable").append(TableInfo);
}
function LoginRecord() {
	$.ajax({
		url: httpurl+"/SelectLoginRecordList",
		cache: false,
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		data: {
			"page":1,
			"pagesize":10,
			"StartTime":'',
			"EndTime":'',
		},
		success: function(data){
			// console.log("===SelectLoginRecordList==="+JSON.stringify(data));
			if(data.rtnCode==200){
				let dataList=data.data;
				HandleLoginRecord(dataList);
			}else{
				top.layer.alert("访问接口失败！！",function(index){
					layer.close(index);
				});
			}
		}
	});
}
function HandleLoginRecord(dataInfo) {
	let TbInfo="";
	let TableInfo='<tr>' +
						'<td colspan="2" class="bg_gray"><p class="float_left">登录记录</p> <a class="float_right" href="sys/loginRecord.html">更多》</a>' +
						'</td>' +
					'</tr>';
	$(".LoginRecord").append(TableInfo);
	for(let i=0;i<dataInfo.length;i++){
		if(i%2==0){
			$(".LoginRecord").append("<tr></tr>");
		}
		TbInfo='<td>'+
					'<div class="width40 float_left">'+dataInfo[i].username+'</div>'+
					'<div>'+dataInfo[i].intime+'</div>'+
				'</td>';
		$(".LoginRecord tr:last-child").append(TbInfo);
	}
}

function Productlist(){
	$.ajax({
		url: httpurl+"/Productlistpc",
		cache: false,
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		data: {
			"pageNo":1,
			"pageSize":10,
			"typeid":0,
			"inputname":'',
		},
		success: function(data){
			if(data.rtnCode==200){
				let dataList=data.data.list;
				HandleData(dataList);
			}
		}
	});
}
function HandleData(dataInfo){
	let info='<tr>'+
			'<td>排名</td>'+
			'<td>商品名称</td>'+
			'<td>销量</td>'+
		'</tr>';
	for(let i=0;i<dataInfo.length;i++){
		info+='<tr>' +
			'<td><span class="btn-danger display_table margin_auto width20">'+(i+1)+'</span></td>' +
			'<td><span class=" display_table margin_auto width60">'+dataInfo[i].productEntity.title+'</span></td>' +
			'<td><span class=" display_table margin_auto width20">'+dataInfo[i].productEntity.sales+'</span></td>' +
			'</tr>';

	}
	$("#ProductTable").html(info);
}

function TitleInfo(){
	$.ajax({
		url: httpurl+"/SelectHeaderInfo",
		cache: false,
		headers: {
			"Access-Control-Allow-Origin": "*",
			"Access-Control-Allow-Methods": "*",
			"Access-Control-Allow-Headers": "Authorization",
			"Authorization": GetTokenInfo()
		},
		contentType : 'application/json',
		success: function (data) {
			let dataInfo=data.data;
			var allSumMoney=unitConvert(dataInfo.allSumMoney);
			var allCountNum=unitConvert(dataInfo.allCountNum);
			var todaySumMoney=unitConvert(dataInfo.todaySumMoney);
			var todayCountNum=unitConvert(dataInfo.todayCountNum);
			$("#allSumMoney").html(allSumMoney.num+allSumMoney.unit+"元");
			$("#allCountNum").html(Number(allCountNum.num)+allCountNum.unit+"笔");
			$("#todaySumMoney").html(todaySumMoney.num+todaySumMoney.unit+"元");
			$("#todayCountNum").html(Number(todayCountNum.num)+todayCountNum.unit+"笔");

		}
	});
}





